package com.young.interfaces.log.model;

import com.young.interfaces.ums.model.User;

import java.util.Arrays;
import java.util.Date;
import java.util.Map;

/**
 * 日志传输对象,用于日志控制器和日志处理器之间传递参数
 * Created by rookie on 2017/11/10.
 */
public class LogDTO implements java.io.Serializable {
    private static final long serialVersionUID = 1L;
    private String uuid;//唯一编号
    //private Log log;//注解信息,由于注解在序列化时存在问题,所以这里不再使用
    private String businessId;//业务id,供业务方自定义

    //基础信息/注解信息 START
    private String appName;//应用名,对应Log中的app(app无效时默认使用配置文件中的appName)
    private String key;//方法标识,对应Log中的key(key无效时默认使用:类全限定名.方法名)
    private String logContent;//描述/说明,对应Log中的value
    private String[] logHandler;//日志处理器,对应Log中的handler
    private String[] logTags;//标签,对应Log中的tags
    //基础信息/注解信息 END

    //链路信息 START
    private String traceId;//链路追踪id
    private boolean sampling;//是否采样
    private String spanId;//rpc调用的子链id
    private String parentId;//rpc调用的父链id
    private Date cs;//调用端发送调用请求的时间
    private Date sr;//服务端接收调用请求的时间,也就是下面的beginTime
    private Date ss;//服务端发送响应的时间,也就是下面的endTime
    private Date cr;//调用端接收响应的时间
    private String cip;//调用端ip
    private String sip;//服务端ip
    //链路信息 END

    //方法执行信息 START
    private String className;//类名
    private String methodName;//方法名
    private Date beginTime;//开始时间,分布式链路下的sr
    private Date endTime;//结束时间,分布式链路下的ss
    private long ms;//方法执行耗时(毫秒)
    private Date logTime;//日志处理时间
    private String serverIp;//服务器ip
    private Exception exception;//请求执行后产生的异常(正常执行则为null)
    private Object[] params;//方法入参
    private Object result;//方法出参
    //方法执行信息 END

    //用户端信息(适用于web接口) START
    private User loginUser;//操作用户
    private String clientIp;//用户ip
    private String os;//用户操作系统信息
    private String browser;//用户浏览器信息
    private String scheme;//请求的协议,http/https等
    private String host;//请求的host
    private Integer port;//请求的端口号
    private String uri;//请求的uri
    private String url;//请求的url
    private String method;//请求方式,post/get等
    private String referer;//请求头中的referer
    private String origin;//请求头中的origin
    private Map<String, Object> requestParam;//请求参数,LogUtil.getParameterFromRequest(request)
    //用户端信息 END

    private Map<String, Object> extParam;//扩展参数,暂时没有使用此字段

    /**
     * 链路根log标识, 在移除log时若等于根log, 校验是否全部log都remove完毕(没有bug的情况下是应该只剩下根log的)
     */
    private boolean spanFirstFlag;

    @Override
    public String toString() {
        return "LogDTO{" +
                "uuid='" + uuid + '\'' +
                //", log=" + log +
                ", businessId='" + businessId + '\'' +
                ", traceId='" + traceId + '\'' +
                ", sampling=" + sampling +
                ", spanId='" + spanId + '\'' +
                ", parentId='" + parentId + '\'' +
                ", cs=" + cs +
                ", sr=" + sr +
                ", ss=" + ss +
                ", cr=" + cr +
                ", cip='" + cip + '\'' +
                ", sip='" + sip + '\'' +
                ", appName='" + appName + '\'' +
                ", key='" + key + '\'' +
                ", className='" + className + '\'' +
                ", methodName='" + methodName + '\'' +
                ", beginTime=" + beginTime +
                ", endTime=" + endTime +
                ", ms=" + ms +
                ", logTime=" + logTime +
                ", serverIp='" + serverIp + '\'' +
                ", exception=" + exception +
                ", params=" + Arrays.toString(params) +
                ", result=" + result +
                ", loginUser=" + loginUser +
                ", clientIp='" + clientIp + '\'' +
                ", os='" + os + '\'' +
                ", browser='" + browser + '\'' +
                ", scheme='" + scheme + '\'' +
                ", host='" + host + '\'' +
                ", port=" + port +
                ", uri='" + uri + '\'' +
                ", url='" + url + '\'' +
                ", method='" + method + '\'' +
                ", referer='" + referer + '\'' +
                ", origin='" + origin + '\'' +
                ", requestParam=" + requestParam +
                ", extParam=" + extParam +
                ", spanFirstFlag=" + spanFirstFlag +
                '}';
    }

    public String getUuid() {
        return uuid;
    }

    public void setUuid(String uuid) {
        this.uuid = uuid;
    }

    public String getServerIp() {
        return serverIp;
    }

    public void setServerIp(String serverIp) {
        this.serverIp = serverIp;
    }

    public long getMs() {
        return ms;
    }

    public void setMs(long ms) {
        this.ms = ms;
    }

   /* public Log getLog() {
        return log;
    }

    public void setLog(Log log) {
        this.log = log;
    }*/

    public User getLoginUser() {
        return loginUser;
    }

    public void setLoginUser(User loginUser) {
        this.loginUser = loginUser;
    }

    public Date getBeginTime() {
        return beginTime;
    }

    public void setBeginTime(Date beginTime) {
        this.beginTime = beginTime;
    }

    public Date getEndTime() {
        return endTime;
    }

    public void setEndTime(Date endTime) {
        this.endTime = endTime;
    }


    public String getClientIp() {
        return clientIp;
    }

    public void setClientIp(String clientIp) {
        this.clientIp = clientIp;
    }

    public String getOs() {
        return os;
    }

    public void setOs(String os) {
        this.os = os;
    }

    public String getBrowser() {
        return browser;
    }

    public void setBrowser(String browser) {
        this.browser = browser;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public Date getLogTime() {
        return logTime;
    }

    public void setLogTime(Date logTime) {
        this.logTime = logTime;
    }

    public Exception getException() {
        return exception;
    }

    public void setException(Exception exception) {
        this.exception = exception;
    }

    public Map<String, Object> getRequestParam() {
        return requestParam;
    }

    public void setRequestParam(Map<String, Object> requestParam) {
        this.requestParam = requestParam;
    }

    public String getClassName() {
        return className;
    }

    public void setClassName(String className) {
        this.className = className;
    }

    public String getMethodName() {
        return methodName;
    }

    public void setMethodName(String methodName) {
        this.methodName = methodName;
    }

    public Map<String, Object> getExtParam() {
        return extParam;
    }

    public void setExtParam(Map<String, Object> extParam) {
        this.extParam = extParam;
    }

    public Object getResult() {
        return result;
    }

    public void setResult(Object result) {
        this.result = result;
    }

    public String getUri() {
        return uri;
    }

    public void setUri(String uri) {
        this.uri = uri;
    }

    public String getHost() {
        return host;
    }

    public void setHost(String host) {
        this.host = host;
    }

    public Integer getPort() {
        return port;
    }

    public void setPort(Integer port) {
        this.port = port;
    }

    public String getScheme() {
        return scheme;
    }

    public void setScheme(String scheme) {
        this.scheme = scheme;
    }

    public String getMethod() {
        return method;
    }

    public void setMethod(String method) {
        this.method = method;
    }

    public String getReferer() {
        return referer;
    }

    public void setReferer(String referer) {
        this.referer = referer;
    }

    public String getOrigin() {
        return origin;
    }

    public void setOrigin(String origin) {
        this.origin = origin;
    }

    public String getTraceId() {
        return traceId;
    }

    public void setTraceId(String traceId) {
        this.traceId = traceId;
    }

    public String getSpanId() {
        return spanId;
    }

    public void setSpanId(String spanId) {
        this.spanId = spanId;
    }

    public String getParentId() {
        return parentId;
    }

    public void setParentId(String parentId) {
        this.parentId = parentId;
    }

    public Date getCs() {
        return cs;
    }

    public void setCs(Date cs) {
        this.cs = cs;
    }

    public Date getSr() {
        return sr;
    }

    public void setSr(Date sr) {
        this.sr = sr;
    }

    public Date getSs() {
        return ss;
    }

    public void setSs(Date ss) {
        this.ss = ss;
    }

    public Date getCr() {
        return cr;
    }

    public void setCr(Date cr) {
        this.cr = cr;
    }

    public String getCip() {
        return cip;
    }

    public void setCip(String cip) {
        this.cip = cip;
    }

    public String getSip() {
        return sip;
    }

    public void setSip(String sip) {
        this.sip = sip;
    }

    public boolean isSampling() {
        return sampling;
    }

    public void setSampling(boolean sampling) {
        this.sampling = sampling;
    }

    public String getBusinessId() {
        return businessId;
    }

    public void setBusinessId(String businessId) {
        this.businessId = businessId;
    }

    public String getAppName() {
        return appName;
    }

    public void setAppName(String appName) {
        this.appName = appName;
    }

    public Object[] getParams() {
        return params;
    }

    public void setParams(Object[] params) {
        this.params = params;
    }

    public String getKey() {
        return key;
    }

    public void setKey(String key) {
        this.key = key;
    }

    public String getLogContent() {
        return logContent;
    }

    public void setLogContent(String logContent) {
        this.logContent = logContent;
    }

    public String[] getLogHandler() {
        return logHandler;
    }

    public void setLogHandler(String[] logHandler) {
        this.logHandler = logHandler;
    }

    public String[] getLogTags() {
        return logTags;
    }

    public void setLogTags(String[] logTags) {
        this.logTags = logTags;
    }

    public boolean isSpanFirstFlag() {
        return spanFirstFlag;
    }

    public void setSpanFirstFlag(boolean spanFirstFlag) {
        this.spanFirstFlag = spanFirstFlag;
    }
}
